package com.repair.servlet.addmodule;

import java.io.IOException;

import javax.servlet.RequestDispatcher;
import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import com.repair.dao.Module.impl.ModuleDao;
import com.repair.domain.Module;

public class AddmoduleServlet extends HttpServlet {

	/**
	 * 
	 */
	private static final long serialVersionUID = -7965600373319932977L;

	@Override
	protected void doGet(HttpServletRequest req, HttpServletResponse resp)
			throws ServletException, IOException {
		doPost(req, resp);

	}

	@Override
	protected void doPost(HttpServletRequest req, HttpServletResponse resp)
			throws ServletException, IOException {

		
		
		String op  = req.getParameter("op");
		if(op == null){
			RequestDispatcher rd = req.getRequestDispatcher("addmodule.jsp");
			rd.forward(req, resp);
		}
		if ("add".equals(op) && op != null) {
			int moduleid = 0;
			String mid = req.getParameter("moduleid");
			moduleid = Integer.parseInt(mid);

			String modulename = req.getParameter("modulename");
			String moduleview = req.getParameter("moduleview");
			ModuleDao service = new ModuleDao();
			Module obj = new Module();
			obj.setModuleid(moduleid);
			obj.setModulename(modulename);
			obj.setModuleview(moduleview);
			service.saveModule(obj);
			
			//resp.sendRedirect("/jsp/mokuaiguanli.jsp");
			RequestDispatcher rd = req.getRequestDispatcher("mokuaiguanli?op=view");
			rd.forward(req, resp);
		}

		
	}
}
